<template>
  <el-dialog title="添加房产" :visible="showDialog" @close="close">
    <el-form ref="form" :model="formData" :rules="rules" label-width="100px">
      <el-form-item label="经纪">
        <el-select v-model="formData" placeholder="Select">
          <el-option
            v-for="item in seletList"
            :key="item.id"
            :label="item.name"
            :value="item.id"
          />

        </el-select>
      </el-form-item>

      <el-form-item label="姓名">
        <el-input v-model="formData.name" />
      </el-form-item>
      <!-- 标签 -->
      <el-form-item label="邮箱">
        <el-input v-model="formData.email" />
      </el-form-item>
      <el-form-item label="电话">

        <el-input v-model="formData.phone" />
      </el-form-item>
      <el-form-item label="微信">
        <el-input v-model="formData.price" />
      </el-form-item>
      <el-form-item label="描述">
        <el-input v-model="formData.desc" type="textarea" />
      </el-form-item>

      <el-form-item label="封面">
        <!-- 放置上传图片 -->
        <Upload />
        <el-input v-model="formData.image" placeholder="强制设置图片跳过上传" />
      </el-form-item>
    </el-form>
    <template v-slot:footer>
      <el-row type="flex" justify="center">
        <el-button type="primary" @click="submit">确定</el-button>
        <el-button @click="close">取消</el-button>
      </el-row>
    </template>
  </el-dialog>
</template>
<script>
import Upload from '@/components/Upload'
import { getMangerList } from '@/api/model/manger'
import { addClients, getClistyInfo, editClifty } from '@/api/model/clients'
export default {
  components: { Upload },
  props: {
    showDialog: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      formData: {
        id: null,
        agent: '', // 经纪人
        category: '', // 分类
        title: '', // 标题
        tags: '', // 标签
        address: '', // 地址
        price: '', // 价格
        desc: '', // 描述
        photos: '', // 图片
        image: '' // 封面
      },
      rules: {
        title: [
          { required: true, message: '标题不能为空！', trigger: 'blur' }
        ],
        desc: [
          { required: true, message: '描述不能为空！', trigger: 'blur' }
        ]
      },
      params: {
        _limit: 50,
        _start: 0
      },
      seletList: []
    }
  },
  created() {
    this.getMangerList()
  },
  methods: {
    // 获取指定用户的数据
    async getClistyInfo(id) {
      this.formData.id = id
      const res = await getClistyInfo(id)
      // console.log(95, res)
      this.formData = res.data
    },
    // 新增
    async submit() {
      if (this.formData.id) {
        const res = await editClifty(this.formData)
        console.log(res)
      } else {
        await addClients(this.formData)
      }

      // console.log(95, res)
      this.close()
      this.$emit('update')
    },

    // 获取客户列表
    async getMangerList() {
      const res = await getMangerList(this.params)

      this.seletList = res.data
      console.log(res.data)
    },
    // 关闭弹窗
    close() {
      this.$emit('update:showDialog', false)
      // 清空数据
      this.formData = {
        agent: '', // 经纪人
        category: '', // 分类
        title: '', // 标题
        tags: '', // 标签
        address: '', // 地址
        price: '', // 价格
        desc: '', // 描述
        photos: '', // 图片
        image: '' // 封面
      }
      // 清空校验规则
      this.$refs.form.resetFields()
    }
  }
}
</script>
<style lang="scss" scoped>

</style>
